<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
        <el-form-item label="案件编号" prop="ajbh">
          <el-input
            v-model="queryParams.ajbh"
            placeholder="请输入案件编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="扣押持有人姓名" prop="hsr">
          <el-input
            v-model="queryParams.hsr"
            placeholder="请输入扣押持有人姓名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="收取开始日期" prop="ksrq">
            <el-date-picker clearable
                v-model="queryParams.ksrq"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择收取开始日期">
            </el-date-picker>
            </el-form-item>
            <el-form-item label="收取截至日期" prop="jsrq">
            <el-date-picker clearable
                v-model="queryParams.jsrq"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择收取截至日期">
            </el-date-picker>
            </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
    <el-form-item>
      <el-radio-group v-model="queryParams.ky_thshzt">  
        <el-radio label="0" @change="handleQuery">待提交</el-radio>
        <el-radio label="1" @change="handleQuery">已提交</el-radio>
      </el-radio-group>
    </el-form-item>
      </el-form>
  
      <!-- <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row> -->
  
      <el-table v-loading="loading" :data="transferList" @selection-change="handleSelectionChange" @row-dblclick="doubleclick">
        <el-table-column label="序号" align="center" prop="xh" />
        <el-table-column label="扣押编号" align="center" prop="ky_bh" width="100"/>
        <el-table-column label="案件编号" align="center" prop="ajbh" width="180"/>
        <el-table-column label="案件名称" align="center" prop="ajmc" width="220"/>
        <el-table-column label="扣押持有人" align="center" prop="ky_kykcyr"  width="100"/>
        <el-table-column label="扣押单位名称" align="center" prop="ky_kydw"  width="180"/>
        <el-table-column label="扣押持有人姓名" align="center" prop="hsr" width="100"/>
        <!-- <el-table-column label="扣押物品类型" align="center" prop="ky_type" width="150">
          <template slot-scope="scope">
          {{ scope.row.ky_type == 1 ? '货币有价证券' : scope.row.ky_type == 2 ? '其他' : '' }}
        </template>
        </el-table-column>
        <el-table-column label="扣押物品名称" align="center" prop="ky_mc" width="180"/>
        <el-table-column label="扣押物品数量" align="center" prop="ky_sl" width="100"/> -->
        <el-table-column label="扣押收取金额" align="center" prop="kyje" width="100"/>
        <el-table-column label="扣押收取方式" align="center" prop="ky_sqfs" width="100"/>
        <el-table-column label="币种" align="center" prop="kydw"  width="100"/>
        <el-table-column label="扣押收取状态" align="center" prop="ky_sqzt" width="100">
          <template slot-scope="scope">
          {{ scope.row.ky_sqzt == 0 ? '未收取' : scope.row.ky_sqzt == 1 ? '已收取' : '' }}
        </template>
        </el-table-column>
        <el-table-column label="扣押收取操作人" align="center" prop="ky_sqczr" width="180"/>
        <el-table-column label="扣押收取日期" align="center" prop="ky_sqrq" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.ky_sqrq, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="扣押款退还金额" align="center" prop="ky_thje" width="100"/>
        <el-table-column label="扣押款退还状态" align="center" prop="ky_thzt" width="100">
          <template slot-scope="scope">
          {{ scope.row.ky_thzt == 0 ? '未退还' : scope.row.ky_thzt == 1 ? '已退还' : '' }}
        </template>
        </el-table-column>
        <el-table-column label="办案人" align="center" prop="ky_thczr" width="100"/>
        <el-table-column label="扣押款提交日期" align="center" prop="ky_thrq" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.ky_thrq, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table>
      

      <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 双击弹窗 -->
    <el-dialog :title="tit" :visible.sync="open" width="75%" @closed="gb">
      <el-form ref="forms" :inline="true" :model="form" :rules="ruless" label-width="auto" :hide-required-asterisk="true"  class="creation demo-form-inline">   
        <el-row :gutter="20">     
          <el-col :span="8">
        <el-form-item label="扣押编号" prop="ky_bh">
          <el-input v-model="form.ky_bh" :disabled="true" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <!-- <el-form-item label="序号">
          <el-input v-model="form.xh" :disabled="true" />
        </el-form-item> -->
        <el-form-item label="案件编号">
          <el-input v-model="form.ajbh" :disabled="true" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item label="案件名称">
          <el-input v-model="form.ajmc" :disabled="true" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
          <!-- <el-col :span="8"> -->
        <el-form-item label="扣押持有人">
          <el-input v-model="form.ky_kykcyr" :disabled="true"  style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
          <!-- </el-col>
          <el-col :span="8"> -->
        <el-form-item label="扣押单位名称">
          <el-input v-model="form.ky_kydw" :disabled="true"  style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item label="扣押持有人姓名">
          <el-input v-model="form.hsr" :disabled="true" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item label="委托人">
          <el-input v-model="form.ky_wtr" :disabled="true" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item label="委托人身份证">
          <el-input v-model="form.ky_wtrsfzh" :disabled="true" style="width: 110%"/>
        </el-form-item>
      </el-col>
        <!-- <el-form-item label="扣押类型">
          <el-input v-model="form.ky_type" :disabled="true"/>
        </el-form-item>
        <el-form-item  v-show="['2'].includes(form.ky_type)" label="扣押物品名称">
          <el-input   v-model="form.ky_mc" :disabled="true"/>
        </el-form-item>
        <el-form-item  v-show="['2'].includes(form.ky_type)" label="扣押物品数量">
          <el-input v-model="form.ky_sl" :disabled="true"/>
        </el-form-item> -->
          <el-col :span="8">
        <el-form-item  label="扣押收取金额">
          <el-input v-model="form.kyje" :disabled="true" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item  label="扣押没收金额">
          <el-input v-model="form.ky_msje" :disabled="true" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item  label="划拨金额">
          <el-input v-model="form.ky_hbje"  :disabled="true" style="width: 110%"/>
        </el-form-item>
          </el-col>
        <el-col :span="8">
        <el-form-item  label="退还金额">
          <el-input v-model="form.ky_thje" placeholder="请输入退还金额" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item label="币种">
          <el-input v-model="form.kydw" :disabled="true"  placeholder="请选择币种" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item  label="退还方式">
          <el-select         
          v-model="form.ky_thfs" style="width: 102%"
          placeholder="请选择退还方式">
            <el-option
            v-for="item in options"
              :key="item.id" 
              :label="item.name" 
              :value="item.name"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item  label="退还账户名称" v-show="form.ky_thfs ==='指定账户'">
          <el-input v-model="form.ky_thzhmc" placeholder="请输入退还账户名称" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item  label="退还开户行" v-show="form.ky_thfs ==='指定账户'">
          <el-input v-model="form.ky_thkhh" placeholder="请输入退还开户行" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item  label="退还银行账号" v-show="form.ky_thfs ==='指定账户'">
          <el-input v-model="form.ky_thzh" placeholder="请输入退还银行账号" style="width: 110%"/>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item label="提交日期" prop="ky_thrq">
          <el-date-picker clearable v-model="form.ky_thrq" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择提交日期"></el-date-picker>
        </el-form-item>
      </el-col>
          <el-col :span="8">
        <el-form-item label="办案人">
          <el-input v-model="form.ky_thczr" placeholder="请输入办案人"  style="width: 110%"/>
        </el-form-item>

      </el-col>
          <el-col :span="8">


        <el-form-item label="附件选择" prop="files">
          <Upload v-model="form.files" :data="{}" acceptTip="*仅图片、PDF类型文件可在线预览"
            multiple></Upload>
        </el-form-item>

      </el-col>
        </el-row>
          </el-form>
          <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm(form)">退还</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    </div>
  </template>
  
  <script>
  import { thList, getTransfer, delTransfer, addTransfer, thSeizure } from "@/api/system/bzjtable";
  import selectMultiple from '@/views/collect/addSecurity/selectMultiple'
  import Upload from '@/views/collect/addSecurity/Upload'
  export default {
    name: "Transfertable",
    data() {
        let amount = (rule, value, callback) => {
      if (value) {
        if (!/^(0|[1-9]\d*)(\s|$|\.\d{1,2}\b)/.test(value)) return callback(new Error('请输入非负数、最多含两位小数'))
        if (value <= 0) return callback(new Error('划拨金额应大于0'))
        if (value > 999999999999.99) return callback(new Error('划拨金额不能超过999999999999.99'))
      } else {
        return callback(new Error('请输入划拨金额'))
      }
      callback()
    }
    let dialogVisible = (rule, val, callback) => {
      if (!val) callback(new Error('请输入手机号'))
      let exp = new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/)
      if (!exp.test(val)) {
        return callback(new Error('手机号格式不对'))
      }
      return callback()
    }
    let dialogVisibleFile = (rule, value, callback) => {
      console.log(value?.length, ';');
      if (rule.required) {
        if (value?.length) {
          callback()
        } else {
          return callback(new Error('请选择文件'))
        }
      }
      callback()
    }
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 日期范围
        dateRange: [],
        // transfer表格数据
        transferList: [],
        clickedRowData: null,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum : 1,
          pageSize : 10,
          ajbh : null,
          hsr : null,
          ky_thshzt : '0',
          ksrq : '',
          jsrq :''
        },
        // 表单参数
        form: {
          xh:null,
          ky_bh:null,
          ajmc:null,
          ajbh:null,
          badw:null,
          ky_kykcyr:null,
          ky_kydw:null,
          hsr:null,
          ky_khh:null,
          ky_yhzh:null,
          kyje:null,
          kydw:null,
          ky_sqfs:null,
          ky_sqzt:null,
          ky_sqshzt:null,
          ky_sqshsj:null,
          ky_sqczr:null,
          ky_sqczrlxfs:null,
          ky_sqrq:null,
          ky_thfs:null,
          ky_thje:null,
          ky_thkhh:null,
          ky_thzhmc:null,
          ky_thzh:null,
          ky_thzt:null,
          ky_thshzt:null,
          ky_thczr:null,
          ky_thrq:null,
          ky_hbje:null,
          ky_hbkhh:null,
          ky_hbyhzh:null,
          ky_hbzt:null,
          ky_hbshzt:null,
          ky_hbczr:null,
          ky_hbrq:null,
          ky_msje:null,
          ky_mszt:null,
          ky_msczr:null,
          ky_msczrlxfs:null,
          ky_msrq:null,
          ky_wtr:null,
          ky_wtrsfzh:null,
          ky_hsrsfzh:null,
          ky_zxbm:null,
          ky_zxzh:null,
          ky_msshzt:null, 
        },
        // 表单校验
        ruless: {
        ky_thje: [{ required: true, validator: amount, trigger: 'change' }],
        files: [{ required: true, validator: dialogVisibleFile, trigger: 'change' }]
        },
        options:[{ id: 1, name: '原路退回'},  
        { id: 2, name: '指定账户'},]
      };
    },
    components: {
    selectMultiple,
    Upload
  },
    created() {
      this.getList();
    },
    methods: {
      /** 查询transfer列表 */
      getList() {
        this.loading = true;
        thList(this.queryParams).then(response => {
          this.transferList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
       },
        /**双击操作 */
        doubleclick(row,event){
        this.form = row;
        if(this.form.ky_thje ==0){
          this.form.ky_thje = row.kyje - row.ky_msje;        
        }
        this.tit = "扣押款退还";
        this.open = true;
        },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      gb() {
      this.getList();
    },
      // 表单重置
      reset() {
        this.form = {
          xh:null,
          ky_bh:null,
          ajmc:null,
          ajbh:null,
          badw:null,
          ky_kykcyr:null,
          ky_kydw:null,
          hsr:null,
          ky_khh:null,
          ky_yhzh:null,
          kyje:null,
          kydw:null,
          ky_sqfs:null,
          ky_sqzt:null,
          ky_sqshzt:null,
          ky_sqshsj:null,
          ky_sqczr:null,
          ky_sqczrlxfs:null,
          ky_sqrq:null,
          ky_thfs:null,
          ky_thje:null,
          ky_thkhh:null,
          ky_thzhmc:null,
          ky_thzh:null,
          ky_thzt:null,
          ky_thshzt:null,
          ky_thczr:null,
          ky_thrq:null,
          ky_hbje:null,
          ky_hbkhh:null,
          ky_hbyhzh:null,
          ky_hbzt:null,
          ky_hbshzt:null,
          ky_hbczr:null,
          ky_hbrq:null,
          ky_msje:null,
          ky_mszt:null,
          ky_msczr:null,
          ky_msczrlxfs:null,
          ky_msrq:null,
          ky_wtr:null,
          ky_wtrsfzh:null,
          ky_hsrsfzh:null,
          ky_zxbm:null,
          ky_zxzh:null,
          ky_msshzt:null, 
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.ky_bh)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.ky_thshzt='0'
        this.resetForm("queryForm");
        this.handleQuery();
      },

      /** 提交按钮 */
      submitForm() {
        this.$refs.forms.validate(valid => {
          if (valid) {
                thSeizure(this.form).then(response => {
                this.$modal.msgSuccess("退还成功");
                this.open = false;
                this.getList();
              });
          } else {
                // 表单验证失败，给出提示信息  
                this.$message.error('退还失败，请上传上传附件！');  
                return false;  
            }
        });
      },
    }
  };
  </script>
    <style>
    .creation {
      .el-form-item {
        margin-bottom: 15px;
      }
      .el-textarea {
        width: 250px;
    
      }
      ::v-deep.el-input__inner {
        width: 250px;
      }
    
      .xx {
        ::v-deep.el-input__inner {
          width: 630px;
        }
      }
    }
    ::v-deep .demo-form-inline .el-input {
      --el-input-width: 220px !important;
    }
    </style>
  